
#include "singleton.h"
#include "debug_macro.h"


#include <iostream>
#include <fstream>

namespace DesignMode{

	using namespace std;

	const std::string StaticLogger::kLogLevelDebug = "DEBUG";
	const std::string StaticLogger::kLogLevelInfo = "INFO";
	const std::string StaticLogger::kLogLevelError = "ERROR";

	const char* const StaticLogger::kLogFileName = "log.out";
	bool StaticLogger::sInitialized = false;

	std::ofstream StaticLogger::sOutputStream;


	void StaticLogger::log(const std::string& in_message, const std::string& in_log_level)
	{

		if (! sInitialized)
		{
			Init();
		}
		sOutputStream << in_log_level.c_str() << " : " << in_message << std::endl;
	}


	void StaticLogger::log(const std::vector<std::string>& in_messages, const std::string& in_log_level)
	{
		for (size_t i =0;i<in_messages.size();i++)
		{
			log(in_messages[i], in_log_level);
		}
	}

	void StaticLogger::tearDown(){
		sOutputStream.close();
		sInitialized = false;
	}

	void StaticLogger::Init(){
		if (! sInitialized)
		{
			sOutputStream.open(kLogFileName, ios_base::app);
			if (! sOutputStream.good())
			{
				std::cerr << "Unable to initialize the Logger\n";
				return;
			}
			sInitialized = true;
		}
	}

	//////////////////////////////////////////////////////////////////////////



	const std::string TrueLogger::kLogLevelDebug = "DEBUG";
	const std::string TrueLogger::kLogLevelInfo = "INFO";
	const std::string TrueLogger::kLogLevelError = "ERROR";

	const char* const TrueLogger::kLogFileName = "log.out";
	TrueLogger TrueLogger::sInstance;

	TrueLogger& TrueLogger::Instance(){
		return sInstance;
	}

	TrueLogger::~TrueLogger(){
		mOutputStream.close();
	}




	void TrueLogger::log(const std::string& in_message, const std::string& in_log_level)
	{

		
		mOutputStream << in_log_level.c_str() << " : " << in_message << std::endl;
	}


	void TrueLogger::log(const std::vector<std::string>& in_messages, const std::string& in_log_level)
	{
		for (size_t i =0;i<in_messages.size();i++)
		{
			log(in_messages[i], in_log_level);
		}
	}

	

	TrueLogger::TrueLogger(){
		mOutputStream.open(kLogFileName, ios_base::app);
		if (! mOutputStream.good())
		{
			std::cerr << "Unable to initialize the Logger\n";
			return;
		}
	}

	//////////////////////////////////////////////////////////////////////////




	
	std::string Player::getName(){
		return "";
	}


	std::string Player::sendInstantMessage(const std::string& inMessage) const{
		return "";
	}

	std::string PlayerProxy::getName(){
		return "";
	}

	std::string PlayerProxy::sendInstantMessage(const std::string& inMessage) const
	{
		return "The player could not be contacted.\n";
	}


	//use the proxy
	bool informWinner(const Player* inPlayer){
		std::string result;
		result = inPlayer->sendInstantMessage("You have won! want to play again ?");
		if (result == "yes")
		{
			std::cout << const_cast<Player*>(inPlayer)->getName() << " wants to play again \n";
			return true;
		}else{
			std::cout << const_cast<Player*>(inPlayer)->getName() << " doesn't wants to play again \n";
			return false;
		}
	}

}